use core::fmt::Alignment::Left;

pub struct Letter {
    text: String,
}

pub struct EmptyEnvelope{

}

pub struct  ClosedEnvelope {
    letter: Letter,
}

pub struct PickupLorryHandle {
    done: bool,
}

impl Letter {
    pub fn new(text: String) -> Self {
        Letter {text: text}
    }
}

impl EmptyEnvelope {
    pub fn wrap(self, letter: Letter) -> ClosedEnvelope {
        ClosedEnvelope {
            letter: letter
        }
    }
}

pub fn buy_prestamped_envlope() -> EmptyEnvelope {
    EmptyEnvelope{}
}

impl PickupLorryHandle {
    pub fn pickup(&mut self, envelop: ClosedEnvelope) {
        println!("送信");
    }

    pub fn done(self) {
    }
}

impl Drop for PickupLorryHandle {
    fn drop(&mut self) {
        println!("信件已送");
    }
}

pub fn order_pickup() -> PickupLorryHandle {
    PickupLorryHandle {
        done: false
    }
}

#[cfg(test)]
mod test {
    use crate::chapter7::design_mode_raii::{Letter, buy_prestamped_envlope, order_pickup};

    #[test]
    fn test() {
        let letter = Letter::new(String::from("Dear RustFest"));
        let envelope = buy_prestamped_envlope();
        let closed_envelop = envelope.wrap(letter);
        let mut lorry = order_pickup();
        lorry.pickup(closed_envelop);
    }
}






